﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using Microsoft.SmartDevice.Connectivity;

namespace RemoteToolApp
{
    public partial class RemoteTool : Form
    {
        public RemoteTool()
        {
            InitializeComponent();
            PopulatePlatfromList();
        }

        private void PopulatePlatfromList()
        {
            DatastoreManager dsmgr = new DatastoreManager(1033);
            Collection<Platform> plats = dsmgr.GetPlatforms();
            foreach (Platform plat in plats)
	        {
                PlatformList.Items.Add(plat);        
	        }
            
        }

        private void PlatformList_SelectedIndexChanged(object sender, EventArgs e)
        {
            Platform plat =((Platform)((ListBox)sender).SelectedItem);
            if (plat != null)
            {

                Collection<Device> devices = plat.GetDevices();
                DeviceList.Items.Clear();
                foreach (Device device in devices)
                {
                    DeviceList.Items.Add(device);
                }
            }


        }

        private void GetInfoButton_Click(object sender, EventArgs e)
        {
            Device selecteddevice = (Device)DeviceList.SelectedItem;
            try
            {
               
                selecteddevice.Connect();
                if (selecteddevice.IsConnected())
                {
                    LogText.Text = "(" + System.DateTime.Now.TimeOfDay.ToString() + ") " +  "Device " + selecteddevice.Name + " connected.  Getting info... " + "\r\n" + LogText.Text;
                    DeviceInfo form2 = new DeviceInfo(selecteddevice);
                    form2.ShowDialog();
                }          
            }
            catch (Exception ex)
            {
                LogText.Text = "(" + System.DateTime.Now.TimeOfDay.ToString() + ") " +  "Exception:  " + ex.Message + "\r\n" + LogText.Text;
            }
        }




        private void button2_Click(object sender, EventArgs e)
        {
            Device device = (Device)DeviceList.SelectedItem;
            try
            {
                device.Connect();
                if (device.IsConnected())
                {
                    LogText.Text = "(" + System.DateTime.Now.TimeOfDay.ToString() + ") " +  "Device " + device.Name + " connected.  Getting processes ... " + "\r\n" + LogText.Text;
                    
                    ProcessManager form3 = new ProcessManager(device);
                    form3.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                LogText.Text = "(" + System.DateTime.Now.TimeOfDay.ToString() + ") " +  "Exception:  " + ex.Message + "\r\n" + LogText.Text;
            }
        }
      


    }
}
